//
//  ImageModel.m
//  ZzzzyManProject
//
//  Created by mac on 16/2/25.
//  Copyright © 2016年 ZzzzyMan@. All rights reserved.
//

#import "ImageModel.h"
#import "ZyNetWorkTools.h"
#import <AVQuery.h>


@interface ImageModel()


@end
@implementation ImageModel

+ (instancetype)imageModelWithDict:(NSDictionary *)dict {
    ImageModel * model = [[ImageModel alloc] init];
    [model setValuesForKeysWithDictionary:dict];
    return model;
}

//+ (NSArray *)imageArr{
//    AVQuery *query = [AVQuery queryWithClassName:@"CycleScroll"];
//    [query getObjectInBackgroundWithId:@"56d6399af3609a005440b3c3" block:^(AVObject *object, NSError *error) {
//        // object 就是 id 为 558e20cbe4b060308e3eb36c 的 Todo 对象实例
//        NSDictionary * dict = (NSDictionary *)object;
//        NSArray * tempArray = dict[@"cycleScroll"];
//        NSMutableArray * arrM = [[NSMutableArray alloc] initWithCapacity:tempArray.count];
//        for (NSDictionary * tempDict in tempArray) {
//            ImageModel * model = [ImageModel imageModelWithDict:tempDict];
//            [arrM addObject:model];
//        }
//        
//    }];
//    return a;
//}

+ (void)imageArrSuccessBlock:(void(^)(NSArray * array))SuccessBlock errorBlock:(void(^)(NSError * error))errorBlock {
    
//    NSString * urlstr = @"https://leancloud.cn:443/1.1/classes/CycleScroll/56d6399af3609a005440b3c3";
//    
//    [[ZyNetWorkTools sharedTools] GET:urlstr parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary * _Nullable responseObject) {
//        
//        NSLog(@"%@",responseObject[@"cycleScroll"]);
//        
//        if (SuccessBlock) {
//            SuccessBlock(responseObject[@"cycleScroll"]);
//        }
//        
//    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//        
//        if (errorBlock) {
//            errorBlock(error);
//        }
//
//        
//    }];
    
    AVQuery *query = [AVQuery queryWithClassName:@"CycleScroll"];
    [query getObjectInBackgroundWithId:@"56d6399af3609a005440b3c3" block:^(AVObject *object, NSError *error) {
        NSLog(@"%@",object);
        NSDictionary * dict = (NSDictionary *)object;
        NSArray * tempArray = dict[@"cycleScroll"];
        NSMutableArray * arrM = [[NSMutableArray alloc] initWithCapacity:tempArray.count];
        for (NSDictionary * tempDict in tempArray) {
            ImageModel * model = [ImageModel imageModelWithDict:tempDict];
            [arrM addObject:model];
        }
        
        if (object) {
            SuccessBlock(arrM.copy);
        }
        else if (error) {
            errorBlock(error);
        }
        
        
    }];
    
}


@end
